package org.smart4j.framework.util;


import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * @author Wangminze
 * @version 2016/12/26
 * Description :  文件操作工具类
 */
public final class FileUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(FileUtil.class);

    /**
     * Description : 获取真实文件名
     * @antuor : Wangminze
     * @version : 2016/12/26
     * @param :
     * @return :
     **/
    public static String getRealFileName(String fileName){
        return FilenameUtils.getName(fileName);
    }

    /**
     * Description : 创建文件
     * @antuor : Wangminze
     * @version : 2016/12/26
     * @param :
     * @return :
     **/
    public static File createFile(String filePath){
        File file;
        try {
            file = new File(filePath);
            File parentDir = file.getParentFile();
            if (!parentDir.exists()){
                FileUtils.forceMkdir(parentDir);
            }
        }catch (Exception e){
            LOGGER.error("Create file failure", e);
            throw new RuntimeException(e);
        }
        return file;
    }


}
